docker

您所在的位置:网站首页 docker compose nacos ip docker

docker

2024-07-10 00:45| 来源: 网络整理| 查看: 265

docker-compose 部署nacos单机/集群 单机模式docker-compose.yml创建nacos目录 在conf创建application.properties集群docker-compose.ymlconf测试

单机模式 docker-compose.yml version: '3' services: mysql-master: image: mysql:5.7 container_name: mysql-master restart: always privileged: true ports: - "3306:3306" environment: - MYSQL_ROOT_PASSWORD=886291 - character-set-server=utf8mb4 - collation-server=utf8mb4_unicode_ci - default-authentication-plugin=mysql_native_password volumes: - /root/mysql/master/conf/my.cnf:/etc/mysql/my.cnf - /root/mysql/master/logs:/var/log/mysql - /root/mysql/master/data:/var/lib/mysql nacos1: image: nacos/nacos-server:1.2.1 container_name: nacos1 restart: always privileged: true depends_on: - mysql-master environment: PREFER_HOST_MODE: 10.10.9.155 #如果支持主机名可以使用hostname,否则使用ip,默认也是ip SPRING_DATASOURCE_PLATFORM: mysql #数据源平台 仅支持mysql或不保存empty # 单节点模式 #MODE: standalone #集群中其它节点[ip1:port ip2:port ip3:port] NACOS_SERVERS: 10.10.9.155:8848 10.10.9.156:8848 10.10.9.157:8848 MYSQL_SERVICE_HOST: 172.24.0.4 MYSQL_SERVICE_DB_NAME: nacos MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_USER: root MYSQL_SERVICE_PASSWORD: 886291 NACOS_APPLICATION_PORT: 8848 NACOS_SERVER_IP: 10.10.9.155 NACOS_APPLICATION_PORT: 8848 JVM_XMS: 1024m JVM_XMX: 1024m JVM_MMS: 320m TOMCAT_ACCESSLOG_ENABLED: false volumes: - /root/nacos/standalone-logs/:/home/nacos/logs - /root/nacos/plugins/:/home/nacos/plugins - /root/nacos/conf/application.properties:/home/nacos/conf/application.properties ports: - "8848:8848"

其它节点将nacos1修改为nacos2等

创建nacos目录 drwxr-xr-x 2 root root 4096 Jan 13 10:24 conf drwxr-xr-x 2 root root 4096 Dec 3 16:51 plugins drwxr-xr-x 2 root root 4096 Jan 13 10:25 standalone-logs 在conf创建application.properties # # Copyright 1999-2018 Alibaba Group Holding Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #*************** Spring Boot Related Configurations ***************# ### Default web context path: server.servlet.contextPath=/nacos ### Default web server port: server.port=8848 #*************** Network Related Configurations ***************# ### If prefer hostname over ip for Nacos server addresses in cluster.conf: # nacos.inetutils.prefer-hostname-over-ip=false ### Specify local server's IP: # nacos.inetutils.ip-address= #*************** Config Module Related Configurations ***************# ### If user MySQL as datasource: # spring.datasource.platform=mysql ### Count of DB: # db.num=1 ### Connect URL of DB: # db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC # db.user=nacos # db.password=nacos #*************** Naming Module Related Configurations ***************# ### Data dispatch task execution period in milliseconds: # nacos.naming.distro.taskDispatchPeriod=200 ### Data count of batch sync task: # nacos.naming.distro.batchSyncKeyCount=1000 ### Retry delay in milliseconds if sync task failed: # nacos.naming.distro.syncRetryDelay=5000 ### If enable data warmup. If set to false, the server would accept request without local data preparation: # nacos.naming.data.warmup=true ### If enable the instance auto expiration, kind like of health check of instance: # nacos.naming.expireInstance=true nacos.naming.empty-service.auto-clean=true nacos.naming.empty-service.clean.initial-delay-ms=50000 nacos.naming.empty-service.clean.period-time-ms=30000 #*************** CMDB Module Related Configurations ***************# ### The interval to dump external CMDB in seconds: # nacos.cmdb.dumpTaskInterval=3600 ### The interval of polling data change event in seconds: # nacos.cmdb.eventTaskInterval=10 ### The interval of loading labels in seconds: # nacos.cmdb.labelTaskInterval=300 ### If turn on data loading task: # nacos.cmdb.loadDataAtStart=false #*************** Metrics Related Configurations ***************# ### Metrics for prometheus #management.endpoints.web.exposure.include=* ### Metrics for elastic search managementrics.export.elastic.enabled=false #managementrics.export.elastic.host=http://localhost:9200 ### Metrics for influx managementrics.export.influx.enabled=false #managementrics.export.influx.db=springboot #managementrics.export.influx.uri=http://localhost:8086 #managementrics.export.influx.auto-create-db=true #managementrics.export.influx.consistency=one #managementrics.export.influx.compressed=true #*************** Access Log Related Configurations ***************# ### If turn on the access log: # 关闭tomcat访问日志,防止造成磁盘不足 server.tomcat.accesslog.enabled=false ### The access log pattern: server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i ### The directory of access log: server.tomcat.basedir= #*************** Access Control Related Configurations ***************# ### If enable spring security, this option is deprecated in 1.2.0: #spring.security.enabled=false ### The ignore urls of auth, is deprecated in 1.2.0: nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/** ### The auth system to use, currently only 'nacos' is supported: nacos.core.auth.system.type=nacos ### If turn on auth system: nacos.core.auth.enabled=false ### The token expiration in seconds: nacos.core.auth.default.token.expire.seconds=18000 ### The default token: nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789 ### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay. nacos.core.auth.caching.enabled=true #*************** Istio Related Configurations ***************# ### If turn on the MCP server: nacos.istio.mcp.server.enabled=false ###*************** Add from 1.3.0 ***************### #*************** Core Related Configurations ***************# ### set the WorkerID manually # nacos.core.snowflake.worker-id= ### Member-MetaData # nacos.core.member.meta.site= # nacos.core.member.meta.adweight= # nacos.core.member.meta.weight= ### MemberLookup ### Addressing pattern category, If set, the priority is highest # nacos.core.member.lookup.type=[file,address-server,discovery] ## Set the cluster list with a configuration file or command-line argument # nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809 ## for DiscoveryMemberLookup # If you want to use cluster node self-discovery, turn this parameter on # nacos.member.discovery=false ## for AddressServerMemberLookup # Maximum number of retries to query the address server upon initialization # nacos.core.address-server.retry=5 #*************** JRaft Related Configurations ***************# ### Sets the Raft cluster election timeout, default value is 5 second # nacos.core.protocol.raft.data.election_timeout_ms=5000 ### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute # nacos.core.protocol.raft.data.snapshot_interval_secs=30 ### Requested retries, default value is 1 # nacos.core.protocol.raft.data.request_failoverRetries=1 ### raft internal worker threads # nacos.core.protocol.raft.data.core_thread_num=8 ### Number of threads required for raft business request processing # nacos.core.protocol.raft.data.cli_service_thread_num=4 ### raft linear read strategy, defaults to index # nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe ### rpc request timeout, default 5 seconds # nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000 集群

准备三台服务器192.168.1.155:8848, 192.168.1.156:8848, 192.168.1.157:8848;

docker-compose.yml

在三台服务器分别创建docker-compose.yml文件,注意配置PREFER_HOST_MODE为各自节点的IP。

version: "3" services: nacos3: image: nacos/nacos-server:1.2.1 container_name: nacos3 restart: always privileged: true environment: PREFER_HOST_MODE: 192.168.1.155 #如果支持主机名可以使用hostname,否则使用ip,默认也是ip SPRING_DATASOURCE_PLATFORM: mysql #数据源平台 仅支持mysql或不保存empty MYSQL_SERVICE_HOST: 192.168.1.151 MYSQL_SERVICE_DB_NAME: nacos MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_USER: root MYSQL_SERVICE_PASSWORD: 886291 NACOS_SERVER_IP: 10.10.9.157 NACOS_APPLICATION_PORT: 8848 #集群中其它节点[ip1:port ip2:port ip3:port] NACOS_SERVERS: 192.168.1.155:8848 192.168.1.156:8848 192.168.1.157:8848 JVM_XMS: 1024m JVM_XMX: 1024m volumes: - /root/nacos/standalone-logs/:/home/nacos/logs - /root/nacos/plugins/:/home/nacos/plugins - /root/nacos/conf/application.properties:/home/nacos/conf/application.properties ports: - "8848:8848" conf

创建/root/nacos/conf/application.properties文件内容如下:

server.servlet.contextPath=/nacos server.port=8848 spring.datasource.platform=mysql db.num=1 # 这里要对应ip,以及对应的数据库 db.url.0=jdbc:mysql://192.168.1.151:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true db.user=root db.password=886291 nacos.cmdb.dumpTaskInterval=3600 nacos.cmdb.eventTaskInterval=10 nacos.cmdb.labelTaskInterval=300 nacos.cmdb.loadDataAtStart=false managementrics.export.elastic.enabled=false managementrics.export.influx.enabled=false # 关闭tomcat访问日志,防止造成磁盘不足 server.tomcat.accesslog.enabled=false server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/ console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/** nacos.naming.distro.taskDispatchThreadCount=1 nacos.naming.distro.taskDispatchPeriod=200 nacos.naming.distro.batchSyncKeyCount=1000 nacos.naming.distro.initDataRatio=0.9 nacos.naming.distro.syncRetryDelay=5000 nacos.naming.data.warmup=true nacos.naming.expireInstance=true 测试

分别启动三个节点上的容器,浏览器输入链接: http://ip:8848/nacos 后进入集群管理菜单→节点管理,可以看到三个节点的信息。 在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3